let video = document.getElementById('video')
let btn = document.getElementById('btn')

console.log('res')
alert('进入页面')

btn.onclick = function () {
  alert('点击了按钮')
  navigator.mediaDevices
    .getUserMedia({
      audio: false,
      video: { facingMode: 'environment' }
    })
    .then(function (stream) {
      /* 使用这个 stream stream */
      console.log(stream, 'res')
      alert('res')
      video.srcObject = stream
      video.onloadedmetadata = function (e) {
        video.play()
      }
    })
    .catch(function (err) {
      /* 处理 error */
      console.log(err, 'err')
      alert('err')
    })
}
